package com.example.myapplication.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.myapplication.R;
import com.example.myapplication.been.MusicInfo;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * Created by Lx on 2019/3/21.
 */

public class CollapsingToolbarLayoutDemo extends AppCompatActivity {
    RecyclerView recyclerView;
    BaseQuickAdapter<MusicInfo, BaseViewHolder> baseQuickAdapter;
    List<MusicInfo> list;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collapsingtoobarlayout);
        Toolbar mToolbar = findViewById(R.id.toolbar);
        recyclerView = findViewById(R.id.recyclerView);
        list = new ArrayList<>();
        setSupportActionBar(mToolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        //使用CollapsingToolbarLayout必须把title设置到CollapsingToolbarLayout上，设置到Toolbar上则不会显示
        CollapsingToolbarLayout mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar_layout);
        mCollapsingToolbarLayout.setTitle("Layout");
        //通过CollapsingToolbarLayout修改字体颜色
        mCollapsingToolbarLayout.setExpandedTitleColor(Color.WHITE);//设置还没收缩时状态下字体颜色
        mCollapsingToolbarLayout.setCollapsedTitleTextColor(Color.WHITE);//设置收缩后Toolbar上字体的颜色
        initDate();
    }

    private void initDate() {
        for (int i = 0; i <= 50; i++) {
            MusicInfo musicInfo = new MusicInfo("1", "2");
            list.add(musicInfo);
        }
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        baseQuickAdapter = new BaseQuickAdapter<MusicInfo, BaseViewHolder>(R.layout.item, list) {
            @Override
            protected void convert(BaseViewHolder helper, MusicInfo item) {
                helper.setText(R.id.tv, item.name);
            }
        };
        recyclerView.setAdapter(baseQuickAdapter);
    }
}
